import java.util.ArrayList;
import java.util.List;

class Solution2 {
    List<Integer> path;
    List<List<Integer>> ret;
    public List<List<Integer>> combine(int n, int k) {
        path = new ArrayList<>();
        ret = new ArrayList<>();
        dfs(1, n, k);
        return ret;
    }
    private void dfs(int index, int n, int k) {
        if(path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for(int i = index; i <= n; i++) {
            path.add(i);
            dfs(i+1, n, k);
            path.remove(path.size()-1);
        }
    }
}